package com.jeect.userservice3.service.impl;

import com.jeect.userservice3.domain.User;
import com.jeect.userservice3.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@Service
public class AuthenticationService implements UserDetailsService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if(!StringUtils.isEmpty(username)){
            User user = this.userMapper.getByAccount(username);
            BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
            System.out.println(encoder.encode("123456"));
            return new org.springframework.security.core.userdetails.User(username, user.getLoginPass(),true,true,true,true,
                    AuthorityUtils.commaSeparatedStringToAuthorityList("Admin"));

        }else{
            return null;
        }
    }

}
